package ch.fhnw.qualiscan.core.db;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * HibernateUtil creates the connection to the database.
 * 
 * @author Kevin Mettenberger
 *
 */
public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();
    
    /**
     * Connects to the database
     * 
     * @return returns the session containing the connection to the database to the static variable sessionFactory
     */
    private static SessionFactory buildSessionFactory() {
        try {
           
            return new Configuration().configure().setProperty("hibernate.show_sql", "false").buildSessionFactory();
        }
        catch (Throwable ex) {

            throw new ExceptionInInitializerError(ex);
        }
    }
    
    /**
     * 
     * @return returns the sessionFactoryr variable
     */
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}

